
public class TestProcessor implements Runnable{
	private boolean running=true;
	private boolean available=false;
	private Task task;
	private TestConnect connect;
	public TestProcessor(TestConnect connect){
		this.connect=connect;
	}
	public synchronized void process(Task task){
		
		task.execute();
	}
	public  synchronized void assign(Task task){
		while(available){
			try {
				wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		this.task=task;
		available=true;
		notifyAll();
	}
	
	private synchronized Task await(){
		
		while (!available) {
			try {
				wait();
			}catch (InterruptedException e) {
				
			}
		}
		
		Task task=this.task;
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		available=false;
		notifyAll();
		return task;

	}
	
	public synchronized void run() {
		while(running){
			task=await();
			if(task!=null)
				process(task);
			else{
				
			}
		}
		
	}
	
}
